package cn.iocoder.yudao.module.system.service.ranking;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 排名计算 Service 接口
 *
 * @author 芋道源码
 */
public interface RankingCalculationService {

    /**
     * 计算考试的所有排名
     *
     * @param examId 考试ID
     */
    void calculateAllRankings(Long examId);

    /**
     * 计算校内总分排名
     *
     * @param examId 考试ID
     */
    void calculateSchoolTotalRanking(Long examId);

    /**
     * 计算班级总分排名
     *
     * @param examId 考试ID
     */
    void calculateClassTotalRanking(Long examId);

    /**
     * 计算选科组合排名
     *
     * @param examId 考试ID
     */
    void calculateCombinationRanking(Long examId);

    /**
     * 计算科目校内排名
     *
     * @param examId 考试ID
     * @param subjectName 科目名称
     */
    void calculateSubjectSchoolRanking(Long examId, String subjectName);

    /**
     * 计算科目班级排名
     *
     * @param examId 考试ID
     * @param subjectName 科目名称
     */
    void calculateSubjectClassRanking(Long examId, String subjectName);

    /**
     * 计算所有科目的排名
     *
     * @param examId 考试ID
     */
    void calculateAllSubjectRankings(Long examId);

    /**
     * 获取排名统计信息
     *
     * @param examId 考试ID
     * @return 排名统计信息
     */
    RankingStatistics getRankingStatistics(Long examId);

    /**
     * 获取学生的排名信息
     *
     * @param examId 考试ID
     * @param studentId 学生ID
     * @return 学生排名信息
     */
    StudentRankingInfo getStudentRankingInfo(Long examId, Long studentId);

    /**
     * 获取班级排名列表
     *
     * @param examId 考试ID
     * @param classId 班级ID
     * @return 班级排名列表
     */
    List<StudentRankingInfo> getClassRankingList(Long examId, Long classId);

    /**
     * 获取选科组合排名列表
     *
     * @param examId 考试ID
     * @param subjectCombination 选科组合
     * @return 组合排名列表
     */
    List<StudentRankingInfo> getCombinationRankingList(Long examId, String subjectCombination);

    /**
     * 获取科目排名列表
     *
     * @param examId 考试ID
     * @param subjectName 科目名称
     * @param rankingType 排名类型（school/class）
     * @return 科目排名列表
     */
    List<SubjectRankingInfo> getSubjectRankingList(Long examId, String subjectName, String rankingType);

    /**
     * 重新计算指定学生的排名
     *
     * @param examId 考试ID
     * @param studentId 学生ID
     */
    void recalculateStudentRanking(Long examId, Long studentId);

    /**
     * 验证排名数据的一致性
     *
     * @param examId 考试ID
     * @return 验证结果
     */
    RankingValidationResult validateRankingConsistency(Long examId);

    /**
     * 排名统计信息
     */
    class RankingStatistics {
        private Long examId;
        private Integer totalStudents;
        private Integer totalClasses;
        private Map<String, Integer> combinationCounts;
        private Map<String, RankingRange> subjectRankingRanges;
        private RankingRange totalScoreRange;
        
        // 构造函数
        public RankingStatistics() {}
        
        public RankingStatistics(Long examId, Integer totalStudents, Integer totalClasses,
                               Map<String, Integer> combinationCounts, 
                               Map<String, RankingRange> subjectRankingRanges,
                               RankingRange totalScoreRange) {
            this.examId = examId;
            this.totalStudents = totalStudents;
            this.totalClasses = totalClasses;
            this.combinationCounts = combinationCounts;
            this.subjectRankingRanges = subjectRankingRanges;
            this.totalScoreRange = totalScoreRange;
        }
        
        // Getters and Setters
        public Long getExamId() { return examId; }
        public void setExamId(Long examId) { this.examId = examId; }
        
        public Integer getTotalStudents() { return totalStudents; }
        public void setTotalStudents(Integer totalStudents) { this.totalStudents = totalStudents; }
        
        public Integer getTotalClasses() { return totalClasses; }
        public void setTotalClasses(Integer totalClasses) { this.totalClasses = totalClasses; }
        
        public Map<String, Integer> getCombinationCounts() { return combinationCounts; }
        public void setCombinationCounts(Map<String, Integer> combinationCounts) { this.combinationCounts = combinationCounts; }
        
        public Map<String, RankingRange> getSubjectRankingRanges() { return subjectRankingRanges; }
        public void setSubjectRankingRanges(Map<String, RankingRange> subjectRankingRanges) { this.subjectRankingRanges = subjectRankingRanges; }
        
        public RankingRange getTotalScoreRange() { return totalScoreRange; }
        public void setTotalScoreRange(RankingRange totalScoreRange) { this.totalScoreRange = totalScoreRange; }
    }

    /**
     * 学生排名信息
     */
    class StudentRankingInfo {
        private Long studentId;
        private String studentName;
        private String studentNo;
        private String className;
        private String subjectCombination;
        private BigDecimal totalScore;
        private BigDecimal totalAssignedScore;
        private Integer schoolRank;
        private Integer classRank;
        private Integer combinationRank;
        private Map<String, SubjectScore> subjectScores;
        
        // 构造函数
        public StudentRankingInfo() {}
        
        // Getters and Setters
        public Long getStudentId() { return studentId; }
        public void setStudentId(Long studentId) { this.studentId = studentId; }
        
        public String getStudentName() { return studentName; }
        public void setStudentName(String studentName) { this.studentName = studentName; }
        
        public String getStudentNo() { return studentNo; }
        public void setStudentNo(String studentNo) { this.studentNo = studentNo; }
        
        public String getClassName() { return className; }
        public void setClassName(String className) { this.className = className; }
        
        public String getSubjectCombination() { return subjectCombination; }
        public void setSubjectCombination(String subjectCombination) { this.subjectCombination = subjectCombination; }
        
        public BigDecimal getTotalScore() { return totalScore; }
        public void setTotalScore(BigDecimal totalScore) { this.totalScore = totalScore; }
        
        public BigDecimal getTotalAssignedScore() { return totalAssignedScore; }
        public void setTotalAssignedScore(BigDecimal totalAssignedScore) { this.totalAssignedScore = totalAssignedScore; }
        
        public Integer getSchoolRank() { return schoolRank; }
        public void setSchoolRank(Integer schoolRank) { this.schoolRank = schoolRank; }
        
        public Integer getClassRank() { return classRank; }
        public void setClassRank(Integer classRank) { this.classRank = classRank; }
        
        public Integer getCombinationRank() { return combinationRank; }
        public void setCombinationRank(Integer combinationRank) { this.combinationRank = combinationRank; }
        
        public Map<String, SubjectScore> getSubjectScores() { return subjectScores; }
        public void setSubjectScores(Map<String, SubjectScore> subjectScores) { this.subjectScores = subjectScores; }
    }

    /**
     * 科目排名信息
     */
    class SubjectRankingInfo {
        private Long studentId;
        private String studentName;
        private String studentNo;
        private String className;
        private String subjectName;
        private BigDecimal originalScore;
        private BigDecimal assignedScore;
        private String gradeLevel;
        private Integer schoolRank;
        private Integer classRank;
        
        // 构造函数
        public SubjectRankingInfo() {}
        
        // Getters and Setters
        public Long getStudentId() { return studentId; }
        public void setStudentId(Long studentId) { this.studentId = studentId; }
        
        public String getStudentName() { return studentName; }
        public void setStudentName(String studentName) { this.studentName = studentName; }
        
        public String getStudentNo() { return studentNo; }
        public void setStudentNo(String studentNo) { this.studentNo = studentNo; }
        
        public String getClassName() { return className; }
        public void setClassName(String className) { this.className = className; }
        
        public String getSubjectName() { return subjectName; }
        public void setSubjectName(String subjectName) { this.subjectName = subjectName; }
        
        public BigDecimal getOriginalScore() { return originalScore; }
        public void setOriginalScore(BigDecimal originalScore) { this.originalScore = originalScore; }
        
        public BigDecimal getAssignedScore() { return assignedScore; }
        public void setAssignedScore(BigDecimal assignedScore) { this.assignedScore = assignedScore; }
        
        public String getGradeLevel() { return gradeLevel; }
        public void setGradeLevel(String gradeLevel) { this.gradeLevel = gradeLevel; }
        
        public Integer getSchoolRank() { return schoolRank; }
        public void setSchoolRank(Integer schoolRank) { this.schoolRank = schoolRank; }
        
        public Integer getClassRank() { return classRank; }
        public void setClassRank(Integer classRank) { this.classRank = classRank; }
    }

    /**
     * 科目成绩
     */
    class SubjectScore {
        private BigDecimal originalScore;
        private BigDecimal assignedScore;
        private String gradeLevel;
        private Integer schoolRank;
        private Integer classRank;
        
        // 构造函数
        public SubjectScore() {}
        
        public SubjectScore(BigDecimal originalScore, BigDecimal assignedScore, 
                          String gradeLevel, Integer schoolRank, Integer classRank) {
            this.originalScore = originalScore;
            this.assignedScore = assignedScore;
            this.gradeLevel = gradeLevel;
            this.schoolRank = schoolRank;
            this.classRank = classRank;
        }
        
        // Getters and Setters
        public BigDecimal getOriginalScore() { return originalScore; }
        public void setOriginalScore(BigDecimal originalScore) { this.originalScore = originalScore; }
        
        public BigDecimal getAssignedScore() { return assignedScore; }
        public void setAssignedScore(BigDecimal assignedScore) { this.assignedScore = assignedScore; }
        
        public String getGradeLevel() { return gradeLevel; }
        public void setGradeLevel(String gradeLevel) { this.gradeLevel = gradeLevel; }
        
        public Integer getSchoolRank() { return schoolRank; }
        public void setSchoolRank(Integer schoolRank) { this.schoolRank = schoolRank; }
        
        public Integer getClassRank() { return classRank; }
        public void setClassRank(Integer classRank) { this.classRank = classRank; }
    }

    /**
     * 排名范围
     */
    class RankingRange {
        private BigDecimal maxScore;
        private BigDecimal minScore;
        private BigDecimal avgScore;
        private Integer totalCount;
        
        // 构造函数
        public RankingRange() {}
        
        public RankingRange(BigDecimal maxScore, BigDecimal minScore, 
                          BigDecimal avgScore, Integer totalCount) {
            this.maxScore = maxScore;
            this.minScore = minScore;
            this.avgScore = avgScore;
            this.totalCount = totalCount;
        }
        
        // Getters and Setters
        public BigDecimal getMaxScore() { return maxScore; }
        public void setMaxScore(BigDecimal maxScore) { this.maxScore = maxScore; }
        
        public BigDecimal getMinScore() { return minScore; }
        public void setMinScore(BigDecimal minScore) { this.minScore = minScore; }
        
        public BigDecimal getAvgScore() { return avgScore; }
        public void setAvgScore(BigDecimal avgScore) { this.avgScore = avgScore; }
        
        public Integer getTotalCount() { return totalCount; }
        public void setTotalCount(Integer totalCount) { this.totalCount = totalCount; }
    }

    /**
     * 排名验证结果
     */
    class RankingValidationResult {
        private boolean valid;
        private List<String> errorMessages;
        private List<String> warningMessages;
        private Map<String, Integer> duplicateRanks;
        private Map<String, Integer> missingRanks;
        
        // 构造函数
        public RankingValidationResult() {}
        
        public RankingValidationResult(boolean valid, List<String> errorMessages, 
                                     List<String> warningMessages, 
                                     Map<String, Integer> duplicateRanks,
                                     Map<String, Integer> missingRanks) {
            this.valid = valid;
            this.errorMessages = errorMessages;
            this.warningMessages = warningMessages;
            this.duplicateRanks = duplicateRanks;
            this.missingRanks = missingRanks;
        }
        
        // Getters and Setters
        public boolean isValid() { return valid; }
        public void setValid(boolean valid) { this.valid = valid; }
        
        public List<String> getErrorMessages() { return errorMessages; }
        public void setErrorMessages(List<String> errorMessages) { this.errorMessages = errorMessages; }
        
        public List<String> getWarningMessages() { return warningMessages; }
        public void setWarningMessages(List<String> warningMessages) { this.warningMessages = warningMessages; }
        
        public Map<String, Integer> getDuplicateRanks() { return duplicateRanks; }
        public void setDuplicateRanks(Map<String, Integer> duplicateRanks) { this.duplicateRanks = duplicateRanks; }
        
        public Map<String, Integer> getMissingRanks() { return missingRanks; }
        public void setMissingRanks(Map<String, Integer> missingRanks) { this.missingRanks = missingRanks; }
    }

}